structs in doors - is it possible to use integers or strings as base data?

Hello

Let me beginn with a simple example:

struct XlHorinzontalAlignmentValue {};

XlHorinzontalAlignmentValue xlCenter()        { Buffer b = create(); b = "-4108"; return (XlHorinzontalAlignmentValue addr_(b)) };
XlHorinzontalAlignmentValue xlDistributed()   { Buffer b = create(); b = "-4117"; return (XlHorinzontalAlignmentValue addr_(b)) };
XlHorinzontalAlignmentValue xlJustify()       { Buffer b = create(); b = "-4130"; return (XlHorinzontalAlignmentValue addr_(b)) };
XlHorinzontalAlignmentValue xlLeft()          { Buffer b = create(); b = "-4131"; return (XlHorinzontalAlignmentValue addr_(b)) };
XlHorinzontalAlignmentValue xlRight()         { Buffer b = create(); b = "-4152"; return (XlHorinzontalAlignmentValue addr_(b)) };

void setRangeAlingment(ExcelRange excelRange, XlHorinzontalAlignmentValue xlHorinzontalAlignment) {
    // some code
}

The idea behind this is: There exists a set of constants which shall be only used for a specific function. Other constants are reserved for other functions. The Alignment-Function of an excel range can be feed with a set of 5 integer constants. By assigning this constants a specifc struct, a function is only able to accept this set of constants.

The acutal use of a buffer is only a workaround. It seems to be a better idea if the routine returns an integer or string (perhaps a date or a boolean) value direct.

Any chance to do this?

Best regards

Wolfgang

 


Wolfgang Uhr - Wed Apr 08 03:47:40 EDT 2015

Re: structs in doors - is it possible to use integers or strings as base data?
Mathias Mamsch - Wed Apr 08 10:42:43 EDT 2015

For enums I normally do something like:

struct XlHorinzontalAlignmentValue {};

XlHorinzontalAlignmentValue xlCenter      = addr_ 1
XlHorinzontalAlignmentValue xlDistributed = addr_ 2
XlHorinzontalAlignmentValue xlJustify     = addr_ 3
XlHorinzontalAlignmentValue xlLeft        = addr_ 4
XlHorinzontalAlignmentValue xlRight       = addr_ 5

int XlHorinzontalAlignmentValue_[] = {0, -4108, -4117, -4130, -4131, -4152}
string XlHorinzontalAlignmentStr_[] = {"NULL", "xlCenter", "xlDistributed", "xlJustify", "xlLeft", "xlRight" }

string stringOf (XlHorinzontalAlignmentValue val) { return XlHorinzontalAlignmentStr_[(addr_ val) int]; }
int excelConstOf (XlHorinzontalAlignmentValue val) { return XlHorinzontalAlignmentValue_[(addr_ val) int]; }

print (stringOf xlCenter) " -> " (excelConstOf xlCenter) "\n"

The advantage is, that this way, you can also handle the null values, or even make null a default constant (null = xlCenter) ...

Regards, Mathias